import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from "path"
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [vue(),
  AutoImport({
    resolvers: [ElementPlusResolver()],
  }),
  Components({
    resolvers: [ElementPlusResolver({
      importStyle: 'sass',
    })],
  }),],

  // 如果用到sass的变量，就需要在这里配置
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/style/element.scss" as *;`,
      },
    },
  },

  resolve: {
    alias: {
      // 这里不需要__dirname，直接使用，因为vite3内置了这个变量，用vite2的方式会报错
      "@": resolve("src"),
      "views": resolve("src/views"),
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
    },
  },

  // 这里是代理配置，如果后端设置了跨域，这里可以直接删掉
  server: {
    proxy: {
      '/api': {
        target: "http://49.232.228.211:89/api",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')  
      }
    }
  }
})

